package com.tjsinfo.tjsoa.doc.bo;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.doc.dao.ITDocDocDAO;
import com.tjsinfo.tjsoa.doc.vo.TDocDoc;

public class TDocDocBO implements ITDocDocBO {
	private IQbcDao qbcDao;
	private ITDocDocDAO docDao;

	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	}
	public void setDocDao(ITDocDocDAO docDao) {
		this.docDao = docDao;
	}
	
	public void save(TDocDoc transientInstance) {
		// TODO Auto-generated method stub
		docDao.save(transientInstance);
	}
	
	public TDocDoc findById(String id) {
		// TODO Auto-generated method stub
		return docDao.findById(id);
	}
	
	public List findByExample(TDocDoc instance) {
		// TODO Auto-generated method stub
		return docDao.findByExample(instance);
	}
	
	public void delete(String id) {
		// TODO Auto-generated method stub
		docDao.delete(id);
	}
	
	public void update(TDocDoc transientInstance) {
		// TODO Auto-generated method stub
		docDao.update(transientInstance);
	}	
	
	public List<TDocDoc> selectAll(Integer first, Integer max,
			Integer docMark, HttpServletRequest request) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TDocDoc.class);
		detachedCriteria.add(Restrictions.eq("applyId", String.valueOf(ToolKit.getSessionUser(request).getUser_id())));
		detachedCriteria.add(Restrictions.eq("mark", docMark));
		List<Order> orderlist= new ArrayList<Order>();
		orderlist.add(Order.desc("dateTime"));
		return qbcDao.findPageByCriteria(detachedCriteria, orderlist, max, first).getItems();
	}

	public List<TDocDoc> selectColumn(Integer first, Integer max,
			Integer docMark, String column, String columnName,
			HttpServletRequest request) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TDocDoc.class);
		detachedCriteria.add(Restrictions.eq("applyId", String.valueOf(ToolKit.getSessionUser(request).getUser_id())));
		detachedCriteria.add(Restrictions.eq("mark", docMark));
		detachedCriteria.add(Restrictions.eq(column,columnName));
		List<Order> orderlist= new ArrayList<Order>();
		orderlist.add(Order.desc("dateTime"));
		return qbcDao.findPageByCriteria(detachedCriteria, orderlist, max, first).getItems();
	}
	
	public Integer selectTotal() {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TDocDoc.class);
		
		return  qbcDao.getQueryNumber(detachedCriteria, "id");
	}
	
	
	public List<TDocDoc> cheakOverAll(Integer sealMark,
			HttpServletRequest request) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TDocDoc.class);
		detachedCriteria.add(Restrictions.like("userId", "%" + ToolKit.getSessionUser(request).getUser_id() + "%"));
		detachedCriteria.add(Restrictions.eq("mark", sealMark));
		detachedCriteria.addOrder(Order.desc("dateTime"));
		return qbcDao.getCriteria(detachedCriteria);
	}

	public List<TDocDoc> cheakOverColumn(Integer sealMark, String column,
			String columnName, HttpServletRequest request) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TDocDoc.class);
		detachedCriteria.add(Restrictions.like("userId", "%" + ToolKit.getSessionUser(request).getUser_id() + "%"));
		detachedCriteria.add(Restrictions.eq("mark", sealMark));
		detachedCriteria.add(Restrictions.eq(column,columnName));
		detachedCriteria.addOrder(Order.desc("dateTime"));
		return qbcDao.getCriteria(detachedCriteria);
	}

	public Integer cheakOverTotal() {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TDocDoc.class);
		
		return  qbcDao.getQueryNumber(detachedCriteria, "id");
	}
}
